package com.app.library.base

import io.reactivex.disposables.CompositeDisposable
import io.reactivex.disposables.Disposable

object RxNetLife {
    private val disposableHashMap: LinkedHashMap<String, CompositeDisposable> = LinkedHashMap()

    fun add(key: String?, disposable: Disposable?) {
        if (disposable == null || key == null)
            return
        var compositeDisposable: CompositeDisposable? = disposableHashMap[key]
        if (compositeDisposable == null) {
            compositeDisposable = CompositeDisposable()
            disposableHashMap[key] = compositeDisposable
        }
        compositeDisposable.add(disposable)
    }

    fun clear(key: String?) {
        if (key == null)
            return
        val compositeDisposable = disposableHashMap[key]
        compositeDisposable?.clear()
        disposableHashMap.remove(key)
    }


}
